package thread;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;

public class ThreadPoolDemo {

  public static class MyTask implements Runnable {

    @Override
    public void run() {
      System.out.println(System.currentTimeMillis() + ": Thread ID:" + Thread.currentThread().getId());
      try {
        Thread.sleep(1000L);
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
    }

    public static void main(String[] args) {
      MyTask t = new MyTask();
      ExecutorService es = Executors.newCachedThreadPool();
      for (int i = 0; i < 10; i++) {
        es.submit(t);
      }

      ExecutorService esShedule = Executors.newScheduledThreadPool(2);
      ((ScheduledExecutorService) esShedule).scheduleWithFixedDelay(new Runnable() {
        @Override
        public void run() {
          try {
            Thread.sleep(1000L);
            System.out.println(System.currentTimeMillis() / 1000);
          } catch (InterruptedException e) {
            e.printStackTrace();
          }
        }
      }, 0, 2, TimeUnit.SECONDS);

      BlockingQueue b;
      ReentrantLock r;
    }
  }

}
